<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;

class StoreOrderRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'saler_id'    => 'required|integer|min:1',
            'year'        => 'required|integer|min:0', 
            'customer'    => 'required',
            'amount'      => 'required',
            'real_amount' => 'required',
            'contract_no' => 'exists:contracts,contract_no',
        ];        

        if ($this->get('type') != 2) {
           $rules['web_package'] = 'integer|min:1';
           $rules['languages']   = 'required|array';
        }

        return $rules;
    }

    public function messages()
    {
        return [
            'saler_id.min'        => '您没有选择业务人员',
            'web_package.min'     => '请选择套餐版本',
            'contract_no.exists'  => '合同号不存在',
        ];
    }
}
